package com.chen.app.controller;


import com.chen.app.entity.User;
import com.chen.app.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping("/add")
    public User add(){
        User user = new User();
        user.setName("test");
        user.setAge(18);
        user.setEmail("947796393@qq.com");
        userService.addUser(user);
        return user;
    }

    @RequestMapping("/edit")
    public User edit(){
        User user = new User();
        user.setId(1L);
        user.setAge(26);
        userService.editUser(user);
        return user;
    }

    @RequestMapping("/del")
    public void del(){
        userService.delUser(1L);
    }

    @RequestMapping("/selectOne")
    public User selectOne(){
        return userService.selectById(1L);
    }

    @RequestMapping("/selectAll")
    public List<User> selectAll(){
        return userService.selectList();
    }
}
